﻿Public Class oPromotionDocumentLinePropertyExclusive
    Public Function UpdateJsonPromotionDocumentLinePropertyEx(ByVal id As String, ByVal promotionID As String, _
                                ByVal propertyDetailID As String, _
                                ByVal databaseName As String, ByVal isInsert As Boolean) As String
        Dim connect As New Connection()
        Try
            Dim errMsg As String = connect.setSQLDB(databaseName)
            If errMsg.Length = 0 Then
                Dim params = New Object() {promotionID, propertyDetailID}
                Dim query As New StringBuilder
                If isInsert = True Then
                    query.Append(" IF NOT EXISTS(SELECT 1 FROM oPromotionDocumentLinePropertyExclusive WHERE [PromotionID] = @Param1 AND PropertyDetailID = @Param2)")
                    query.Append(" INSERT INTO [oPromotionDocumentLinePropertyExclusive]")
                    query.Append("  ([PromotionID]")
                    query.Append(" ,[PropertyDetailID])")
                    query.Append(" VALUES (@Param1,@Param2)")
                    Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), params)
                Else
                    query.Append("DELETE  [oPromotionDocumentLinePropertyExclusive] WHERE ")
                    query.Append("  [PromotionID] = @Param1")
                    query.Append("  AND [PropertyDetailID] = @Param2")
                    connect.Object_Execute_SAP(query.ToString(), New Object() {promotionID, propertyDetailID})
                End If
            Else
                Return errMsg
            End If
        Catch ex As Exception

            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function DeleteJsonPromotionDocumentLinePropertyEx(ByVal dataBaseName As String, ByVal id As String) As String
        Dim connect As New Connection()
        Try
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            If errMsg.Length = 0 Then
                Dim params = New Object() {id}
                Dim query As New StringBuilder
                query.Append(" DELETE FROM [oPromotionDocumentLinePropertyExclusive]")
                query.Append("  WHERE ID =  @Param1")
                Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), params)
            Else
                Return errMsg
            End If
        Catch ex As Exception

            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function GetAllPromotionDocumentLinePropertyExByPromotionID(ByVal dataBaseName As String, ByVal propertyID As String, ByVal promotionID As String) As DataSet
        Dim connect As New Connection()
        Try
            Dim ds As New DataSet("oPromotionDocumentLinePropertyExclusive")
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("  SELECT * FROM  oDocLinePropertyDetail T2 LEFT JOIN ( SELECT T1.* FROM oPromotionHeader T0 LEFT JOIN oPromotionDocumentLinePropertyExclusive T1")
                query.Append("  ON T0.PromotionID = T1.PromotionID")
                query.Append("  WHERE T0.PromotionID = @Param1)  T1    ON T2.PropertyDetailID =  T1.PropertyDetailID   ")
                query.Append(" WHERE T2.PropertyID = @Param2")
                ds = connect.ObjectGetAll_Query_SAP(query.ToString(), New Object() {promotionID, propertyID})
            End If
            Return ds
        Catch ex As Exception
            Throw ex
        End Try
    End Function
End Class
